
package dao;

import connection.connectionFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import model.Cursoextensao;

public class CursoExtensaoDao {
               
    Session session;
    Transaction tx; 
    
    public void salvar(Cursoextensao cursoextensao)
    {
      try
      {
          session = new connectionFactory().getSessionFactory();
          tx =  session.beginTransaction();
          session.save(cursoextensao);
          tx.commit();
          session.close();
            
      }
      catch(Exception e)
      {
           e.printStackTrace();
           tx.rollback();
           session.close();
      }
    } 
    
    public void alterar(Cursoextensao cursoextensao)
    {
      try
      {
          session = new connectionFactory().getSessionFactory();
          tx =  session.beginTransaction();
          session.update(cursoextensao);
          tx.commit();
          session.close();
            
      }
      catch(Exception e)
      {
           e.printStackTrace();
           tx.rollback();
           session.close();
      }
    }  
    
    public void excluir(Cursoextensao cursoextensao)
    {
      try
      {
          session = new connectionFactory().getSessionFactory();
          tx =  session.beginTransaction();
          session.delete(cursoextensao);
          tx.commit();
          session.close();
            
      }
      catch(Exception e)
      {
           e.printStackTrace();
           tx.rollback();
           session.close();
      }
    } 
}


